VERSION 5.00
Begin VB.Form frmRefund 
   Caption         =   "תעודת החזר"
   ClientHeight    =   4110
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   8625
   LinkTopic       =   "Form1"
   ScaleHeight     =   4110
   ScaleWidth      =   8625
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox txtCheck 
      Height          =   285
      Index           =   2
      Left            =   1920
      TabIndex        =   28
      Top             =   2640
      Width           =   735
   End
   Begin VB.TextBox txtCheck 
      Height          =   285
      Index           =   1
      Left            =   1920
      TabIndex        =   27
      Top             =   2280
      Width           =   735
   End
   Begin VB.TextBox txtCheck 
      Height          =   285
      Index           =   0
      Left            =   1920
      TabIndex        =   26
      Top             =   1920
      Width           =   735
   End
   Begin VB.ComboBox lstPmtTypes 
      Height          =   315
      Index           =   0
      ItemData        =   "frmRefund.frx":0000
      Left            =   7200
      List            =   "frmRefund.frx":0022
      TabIndex        =   25
      Text            =   "1-מזומן"
      Top             =   1920
      Width           =   1215
   End
   Begin VB.CommandButton cmdOKXML 
      Caption         =   "צור תעודה ב-XML"
      Height          =   375
      Left            =   3000
      TabIndex        =   24
      Top             =   3600
      Width           =   1695
   End
   Begin VB.CommandButton cmdOpenReceipt 
      Caption         =   "Command1"
      Height          =   375
      Left            =   4800
      TabIndex        =   23
      Top             =   3600
      Visible         =   0   'False
      Width           =   2055
   End
   Begin VB.TextBox txtComments 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   120
      TabIndex        =   22
      Top             =   1080
      Width           =   5895
   End
   Begin VB.TextBox txtAccount 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   2
      Left            =   5040
      TabIndex        =   21
      Top             =   2640
      Width           =   2055
   End
   Begin VB.TextBox txtBranch 
      Height          =   285
      Index           =   2
      Left            =   4080
      TabIndex        =   20
      Top             =   2640
      Width           =   855
   End
   Begin VB.TextBox txtCheckDate 
      Height          =   285
      Index           =   2
      Left            =   960
      TabIndex        =   19
      Top             =   2640
      Width           =   855
   End
   Begin VB.TextBox txtAccount 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   1
      Left            =   5040
      TabIndex        =   18
      Top             =   2280
      Width           =   2055
   End
   Begin VB.TextBox txtBranch 
      Height          =   285
      Index           =   1
      Left            =   4080
      TabIndex        =   17
      Top             =   2280
      Width           =   855
   End
   Begin VB.TextBox txtCheckDate 
      Height          =   285
      Index           =   1
      Left            =   960
      TabIndex        =   16
      Top             =   2280
      Width           =   855
   End
   Begin VB.TextBox txtCheckDate 
      Height          =   285
      Index           =   0
      Left            =   960
      TabIndex        =   15
      Top             =   1920
      Width           =   855
   End
   Begin VB.TextBox txtBranch 
      Height          =   285
      Index           =   0
      Left            =   4080
      TabIndex        =   14
      Top             =   1920
      Width           =   855
   End
   Begin VB.TextBox txtAccount 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   0
      Left            =   5040
      TabIndex        =   13
      Top             =   1920
      Width           =   2055
   End
   Begin VB.ComboBox lstCustomers 
      Height          =   315
      Left            =   4560
      Style           =   2  'Dropdown List
      TabIndex        =   12
      Top             =   600
      Width           =   2535
   End
   Begin VB.CommandButton cmdOK 
      Caption         =   "צור תעודת החזר"
      Height          =   375
      Left            =   1320
      TabIndex        =   11
      Top             =   3600
      Width           =   1575
   End
   Begin VB.CommandButton cmdCancel 
      Caption         =   "יציאה"
      Height          =   375
      Left            =   120
      TabIndex        =   10
      Top             =   3600
      Width           =   975
   End
   Begin VB.TextBox txtAmount 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   2
      Left            =   120
      TabIndex        =   9
      Text            =   "0.00"
      Top             =   2640
      Width           =   735
   End
   Begin VB.TextBox txtAmount 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   1
      Left            =   120
      TabIndex        =   8
      Text            =   "0.00"
      Top             =   2280
      Width           =   735
   End
   Begin VB.TextBox txtAmount 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   0
      Left            =   120
      TabIndex        =   7
      Text            =   "0.00"
      Top             =   1920
      Width           =   735
   End
   Begin VB.ComboBox lstBanks 
      Height          =   315
      Index           =   0
      ItemData        =   "frmRefund.frx":0098
      Left            =   2760
      List            =   "frmRefund.frx":00AB
      TabIndex        =   6
      Text            =   "1-הבניה"
      Top             =   1920
      Width           =   1215
   End
   Begin VB.ComboBox lstBanks 
      Height          =   315
      Index           =   1
      ItemData        =   "frmRefund.frx":00E6
      Left            =   2760
      List            =   "frmRefund.frx":00F9
      TabIndex        =   5
      Text            =   "1-הבניה"
      Top             =   2280
      Width           =   1215
   End
   Begin VB.ComboBox lstBanks 
      Height          =   315
      Index           =   2
      ItemData        =   "frmRefund.frx":0134
      Left            =   2760
      List            =   "frmRefund.frx":0147
      TabIndex        =   4
      Text            =   "1-הבניה"
      Top             =   2640
      Width           =   1215
   End
   Begin VB.ComboBox lstPmtTypes 
      Height          =   315
      Index           =   1
      ItemData        =   "frmRefund.frx":0182
      Left            =   7200
      List            =   "frmRefund.frx":01A4
      TabIndex        =   3
      Text            =   "1-מזומן"
      Top             =   2280
      Width           =   1215
   End
   Begin VB.ComboBox lstPmtTypes 
      Height          =   315
      Index           =   2
      ItemData        =   "frmRefund.frx":021A
      Left            =   7200
      List            =   "frmRefund.frx":023C
      TabIndex        =   2
      Text            =   "1-מזומן"
      Top             =   2640
      Width           =   1215
   End
   Begin VB.TextBox datReceiptDate 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   120
      TabIndex        =   1
      Top             =   120
      Width           =   975
   End
   Begin VB.TextBox txtTotalPmt 
      Alignment       =   1  'Right Justify
      Enabled         =   0   'False
      Height          =   285
      Left            =   120
      TabIndex        =   0
      Text            =   "0.00"
      Top             =   3000
      Width           =   1095
   End
   Begin VB.Label Label14 
      Alignment       =   1  'Right Justify
      Caption         =   "סוג התשלום"
      Height          =   255
      Left            =   7320
      TabIndex        =   41
      Top             =   1560
      Width           =   1095
   End
   Begin VB.Label Label13 
      Alignment       =   1  'Right Justify
      Caption         =   "שובר/שיק"
      Height          =   255
      Left            =   2040
      TabIndex        =   40
      Top             =   1560
      Width           =   855
   End
   Begin VB.Label Label11 
      Alignment       =   1  'Right Justify
      Caption         =   "אם הסכום הוא 0 המערכת תתעלם מהשורה"
      Height          =   255
      Left            =   4560
      TabIndex        =   39
      Top             =   3120
      Width           =   3855
   End
   Begin VB.Label Label7 
      Alignment       =   1  'Right Justify
      Caption         =   "פרטי התעודה (מוצגים ללקוח):"
      Height          =   255
      Left            =   5760
      TabIndex        =   38
      Top             =   1080
      Width           =   2655
   End
   Begin VB.Label Label5 
      Alignment       =   1  'Right Justify
      Caption         =   "ת. פרעון/תוקף"
      Height          =   375
      Left            =   720
      TabIndex        =   37
      Top             =   1560
      Width           =   1215
   End
   Begin VB.Label Label4 
      Alignment       =   1  'Right Justify
      Caption         =   "סניף"
      Height          =   255
      Left            =   3960
      TabIndex        =   36
      Top             =   1560
      Width           =   615
   End
   Begin VB.Label Label3 
      Alignment       =   1  'Right Justify
      Caption         =   "מס' ח-ן/כרטיס"
      Height          =   255
      Left            =   5880
      TabIndex        =   35
      Top             =   1560
      Width           =   1335
   End
   Begin VB.Label Label2 
      Alignment       =   1  'Right Justify
      Caption         =   "שם הלקוח:"
      Height          =   255
      Left            =   7320
      TabIndex        =   34
      Top             =   600
      Width           =   1095
   End
   Begin VB.Label Label1 
      Alignment       =   1  'Right Justify
      Caption         =   "טופס יצירת תעודת החזר"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   177
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   5400
      TabIndex        =   33
      Top             =   0
      Width           =   3015
   End
   Begin VB.Label Label6 
      Alignment       =   1  'Right Justify
      Caption         =   "סכום"
      Height          =   375
      Left            =   0
      TabIndex        =   32
      Top             =   1560
      Width           =   735
   End
   Begin VB.Label Label9 
      Alignment       =   1  'Right Justify
      Caption         =   "בנק"
      Height          =   255
      Left            =   3240
      TabIndex        =   31
      Top             =   1560
      Width           =   615
   End
   Begin VB.Label Label15 
      Alignment       =   1  'Right Justify
      Caption         =   "תאריך:"
      Height          =   255
      Left            =   1200
      TabIndex        =   30
      Top             =   120
      Width           =   615
   End
   Begin VB.Label Label16 
      Alignment       =   1  'Right Justify
      Caption         =   "סה""כ החזר:"
      Height          =   255
      Left            =   1440
      TabIndex        =   29
      Top             =   3000
      Width           =   1095
   End
End
Attribute VB_Name = "frmRefund"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Const MOD_NAME = "frmRefund."
Dim m_iRefundNum As Long

Private Sub cmdCancel_Click()
On Error Resume Next
    Unload Me
End Sub


Private Sub cmdOK_Click()
      Const FUNC_NAME = MOD_NAME & "cmdOK_Click"
10    On Error GoTo func_err

          Dim iCustomersID As Long
          Dim iTrxCodesID As Long
          Dim objCaspit As CaspitAPI.Caspit
          Dim V
          
20        If lstCustomers.ListIndex < 0 Then
30            MyErrMsgBox "חובה לבחור בלקוח"
40            Exit Sub
50        End If
60        If CCur(txtTotalPmt.Text) = 0 Then
70            MyErrMsgBox "חובה להכניס תשלום"
80            Exit Sub
90        End If
          
110       iCustomersID = GetCustomerID()
              
          Dim varReceiptLineItems(2) As CaspitAPI.ReceiptLineItem
          
120       Set objCaspit = New CaspitAPI.Caspit
          
          Dim I As Long
          
130       For I = 0 To 2
140           If Len(txtAmount(I)) > 0 Then
150               Set varReceiptLineItems(I) = New CaspitAPI.ReceiptLineItem
160               varReceiptLineItems(I).AccountNumber = txtAccount(I)
170               varReceiptLineItems(I).Amount = CCur(txtAmount(I))
180               If Len(lstBanks(I).Text) > 0 Then
190                   V = Split(lstBanks(I).Text, "-")
200                   varReceiptLineItems(I).Bank = V(0)
210               End If
220               varReceiptLineItems(I).Branch = txtBranch(I)
230               varReceiptLineItems(I).Check = txtCheck(I)
240               If Len(txtCheckDate(I)) > 0 Then varReceiptLineItems(I).CheckDate = txtCheckDate(I)
250               V = Split(lstPmtTypes(I).Text, "-")
260               varReceiptLineItems(I).PaymentTypesID = V(0)
270           End If
280       Next
          
290       objCaspit.CaspitPath = g_strCaspitPath
300       objCaspit.AccessPath = g_strAccessPath
310       objCaspit.DebugMode = g_blnDebug
320       objCaspit.BusinessID = g_iBusinessID
          
330       m_iRefundNum = objCaspit.CreateRefund(iCustomersID, _
              CDate(datReceiptDate), 0, _
              txtComments, varReceiptLineItems)
          
340       Set objCaspit = Nothing
          
350       cmdOpenReceipt.Caption = "הצג קבלה " & m_iRefundNum
360       cmdOpenReceipt.Visible = True
          
370       MyMsgBox "תעודת החזר " & m_iRefundNum & " נוצרה בהצלחה."
              
380   Exit Sub

func_err:
390       MyErrMsgBox "Error " & Err.Number & " in " & FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source & ": " & Err.Description
400       Set objCaspit = Nothing
End Sub

Private Sub cmdOKXML_Click()
      Const FUNC_NAME = MOD_NAME & "cmdOKXML_Click"
10    On Error GoTo func_err
          
          Dim iCustomersID As Long
          Dim iTrxCodesID As Long
          Dim V
          Dim objCaspit As CaspitAPI.Caspit
          Dim strXML As String
          
20        If lstCustomers.ListIndex < 0 Then
30            MyErrMsgBox "חובה לבחור בלקוח"
40            Exit Sub
50        End If
60        If CCur(txtTotalPmt.Text) = 0 Then
70            MyErrMsgBox "חובה להכניס תשלום"
80            Exit Sub
90        End If
          
100       strXML = "<Caspit>" & vbCrLf & "<Document type=""Refund"">" & vbCrLf
          
110       iCustomersID = GetCustomerID()
120       strXML = strXML & "<CustomerID>" & iCustomersID & "</CustomerID>" & vbCrLf
               
130       strXML = strXML & "<DocDate>" & FormatXMLDate(datReceiptDate) & "</DocDate>" & vbCrLf
140       strXML = strXML & "<Total>" & 0 & "</Total>" & vbCrLf
150       strXML = strXML & "<Details>" & txtComments & "</Details>" & vbCrLf
          
          Dim I As Long
          
160       strXML = strXML & vbCrLf & "<ReceiptLineItems>"
170       For I = 0 To 2
180           If CCur(txtAmount(I)) <> 0 Then
190               strXML = strXML & vbCrLf & "<ReceiptLineItem number=""" & I + 1 & """>"
200               strXML = strXML & vbCrLf & "<AccountNumber>" & txtAccount(I) & "</AccountNumber>"
210               strXML = strXML & vbCrLf & "<Amount>" & txtAmount(I) & "</Amount>"
220               strXML = strXML & vbCrLf & "<Bank>" & Split(lstBanks(I).Text, "-")(0) & "</Bank>"
230               strXML = strXML & vbCrLf & "<Branch>" & txtBranch(I) & "</Branch>"
240               strXML = strXML & vbCrLf & "<Check>" & txtCheck(I) & "</Check>"
250               strXML = strXML & vbCrLf & "<CheckDate>" & FormatXMLDate(txtCheckDate(I)) & "</CheckDate>"
260               V = Split(lstPmtTypes(I).Text, "-")
270               strXML = strXML & vbCrLf & "<PaymentTypesID>" & V(0) & "</PaymentTypesID>"
280               strXML = strXML & vbCrLf & "</ReceiptLineItem>"
290           End If
300       Next
310       strXML = strXML & vbCrLf & "</ReceiptLineItems>"
          
320       strXML = strXML & vbCrLf & "</Document>" & vbCrLf & "</Caspit>"

330       Set objCaspit = New CaspitAPI.Caspit
340       objCaspit.CaspitPath = g_strCaspitPath
350       objCaspit.AccessPath = g_strAccessPath
360       objCaspit.DebugMode = g_blnDebug
370       objCaspit.BusinessID = g_iBusinessID
          
380       m_iRefundNum = objCaspit.CreateRefundXML(strXML)
          
390       Set objCaspit = Nothing
          
400       cmdOpenReceipt.Caption = "הצג תעודה החזר " & m_iRefundNum
410       cmdOpenReceipt.Visible = True
          
420       MyMsgBox "תעודת החזר מספר " & m_iRefundNum & " נוצרה בהצלחה."
              
430   Exit Sub

func_err:
440       MyErrMsgBox "Error " & Err.Number & " in " & FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source & ": " & Err.Description
450       Set objCaspit = Nothing
End Sub

Private Sub cmdOpenReceipt_Click()
Const FUNC_NAME = MOD_NAME & "cmdOpenReceipt_Click"
On Error GoTo func_err

    Dim objCaspit As CaspitAPI.Caspit
    
    Set objCaspit = New CaspitAPI.Caspit
    
    objCaspit.CaspitPath = g_strCaspitPath
    objCaspit.AccessPath = g_strAccessPath
    objCaspit.DebugMode = g_blnDebug
    objCaspit.BusinessID = g_iBusinessID
    
    Call objCaspit.DisplayRefund(m_iRefundNum)
    Set objCaspit = Nothing
Exit Sub

func_err:
    MyErrMsgBox "Error " & Err.Number & " in " & FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source & ": " & Err.Description
    Unload Me
End Sub

Private Sub Form_Load()
      Const FUNC_NAME = MOD_NAME & "Form_Load"
10    On Error GoTo func_err
          Dim I As Long
              
20        datReceiptDate = Date

30        PopulateCustomers
          
40    Exit Sub

func_err:
50        MyErrMsgBox "Error " & Err.Number & " in " & Err.Source & ": " & Err.Description
60        Unload Me
End Sub

Private Sub PopulateCustomers()
Const FUNC_NAME = MOD_NAME & "PopulateCustomers"
10    On Error GoTo func_err
    
    Dim V As Variant
    Dim S As String
    Dim I As Long
    
    Dim objCaspit As CaspitAPI.Caspit
    Dim objCustomer As CaspitAPI.Customer
    
20        Set objCaspit = New CaspitAPI.Caspit
    
30        With objCaspit
40            .CaspitPath = g_strCaspitPath
50            .AccessPath = g_strAccessPath
60            .BusinessID = g_iBusinessID
70            .DebugMode = g_blnDebug
80        End With
    
    'We could get the information in XML form
90        S = objCaspit.GetCustomersXML()
    
    'or in an array
100       V = objCaspit.GetCustomers()
    
110       Set objCaspit = Nothing
    
120       If IsEmpty(V) Then Exit Sub
    
130       If UBound(V) < 0 Then
140     Err.Raise 1040, "", "יש ליצור לקוחות לפני שיוצרים חשבונית"
150       End If
    
    'Skip לקוח מזדמן
160       For I = 0 To UBound(V)
170     Set objCustomer = V(I)
180      Call lstCustomers.AddItem(objCustomer.BusinessName & " - [" & objCustomer.CustomersID & "]")
190       Next

200   Exit Sub

func_err:
210       Err.Raise Err.Number, FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source, Err.Description
220       Set objCaspit = Nothing
End Sub


Private Sub txtAmount_LostFocus(Index As Integer)
On Error Resume Next
    txtAmount(Index) = -Abs(CCur(txtAmount(Index)))
    txtTotalPmt.Text = CCur(txtAmount(0)) + CCur(txtAmount(1)) + CCur(txtAmount(2))

End Sub
'---------------------------------------------------------------------------------------
' Procedure : GetCustomerID
' Author    : Dror
' Date      : 11/08/2011
' Purpose   :
'---------------------------------------------------------------------------------------
Function GetCustomerID()
Const FUNC_NAME = MOD_NAME & "GetCustomerID"
10    On Error GoTo func_Error
        Dim V
20        V = Split(lstCustomers.Text, " - [")
30        V = Split(V(UBound(V)), "]")
40        GetCustomerID = CLng(V(0))

50    Exit Function

func_Error:
60        Err.Raise Err.Number, FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source, Err.Description
End Function
